<script>
var maxnum=5,stop=0;
$.getScript("/static/thinkct/js/plupload.js", function() {
uploader = new plupload.Uploader({
//创建实例的构造方法
                runtimes: 'html5,flash,silverlight,html4', //上传插件初始化选用那种方式的优先级顺序
                browse_button: 'browse', // 上传按钮
                url: "/upload/", //上传地址
			    resize: {width: 900},  
				max_retries: 1,
                flash_swf_url: '//statics.huzhan.com/js/Moxie.swf', //flash文件地址
                silverlight_xap_url: '//statics.huzhan.com/js/Moxie.xap', //silverlight文件地址
                filters: {
					prevent_duplicates : true, //不允许队列中存在重复文件
                    max_file_size:'2mb', //最大上传文件大小（格式100b, 10kb, 10mb, 1gb）
                    mime_types: [//允许文件上传类型
                        {title: "选择图片", extensions:'jpg,png,gif'}
                    ]
                },
                multi_selection: true //true:ctrl多文件上传, false 单文件上传
	});
	uploader.init(); //初始化
		//绑定文件添加进队列事件

	uploader.bind('FilesAdded',function(uploader,files){
	var newnum=maxnum-parseInt($('.layui-eva #FileListsuc tr').length+$('.layui-eva #FileListing tr').length),flen=files.length,fhtml,vhtml='',ehtml='';
    if(flen>newnum){ 
	// 最多上传newmaxnum
	     layer.alert("<strong>图片最多能上传"+maxnum+"个</strong>",{icon:2}); 
         uploader.splice(newnum,10000);  
        }
		for(var i = 0; i<=flen; i++){
			if(i==flen){ 
			//更新UI
			 if(ehtml!=''){layer.alert("<strong>以下图片已传过了，不要重复上传</strong><br>"+ehtml,{icon:0});}
			 if(uploader.files.length>0){
			 $('.layui-eva #pluing').show();
			 $(fhtml).appendTo('.layui-eva #FileListing');
			 $('.layui-eva #pluing u').html(uploader.files.length);
			 }
			 return false;
			}
			if(i>=newnum){ 
			// 最多上传newnum
			continue;
		    }
			fname=files[i].name;
			fid=files[i].id;
			var f5name=$.md5(files[i].size+files[i].lastModifiedDate+files[i].type);
			 vhtml='<tr id="file-' + fid +'"><td>' + fname +'</td><td></td><td align="center"><a onclick=deling("'+fid+'")>取消</a></td></tr>'
			 $(".layui-eva #FileListsuc :checkbox").each(function(){     
	         if($(this).val()==f5name){
             vhtml='';
			 uploader.removeFile(fid);
			 ehtml+="【"+fname+"】<br>";
			 return false;
			 }
	         });
             fhtml=fhtml+vhtml;	
		}

	});
	uploader.bind("BeforeUpload",function(uploader,file){
    uploader.setOption("multipart_params",{lastDate:file.lastModifiedDate,osize:file.size,number:'158683876050',filebh:'158683876050',type:'evaluation',menu:'r_buy',filetype:'files',maxnum:maxnum});
    }); 

	uploader.bind("UploadProgress",function(uploader,file){
	//进度
		$('#progress-in').width(uploader.total.percent+"%"); 
		$("#file-"+file.id+" td:eq(2)").html("<b>"+file.percent+"%</b>");
    });
	uploader.bind("FileUploaded",function(uploader, file,info){
	//上传完成后
		 $('#progress-uploaded').html(uploader.total.uploaded);
		 var data =$.parseJSON(info.response);
		 if(data.state!=0){
         $fh=$('#progress ul');
         $fh.show();
		 $('<p><span>'+file.name+'</span><br><b>'+data.state+' >> 继续执行…</b></p>').appendTo($fh);
	     stop=5000;
		 }
    });
	uploader.bind("UploadComplete",function(uploader){
	//全部完成后
		setTimeout("Rs(Rsdata)",stop);
    });
	uploader.bind("Error",function(uploader,err){
	//错误提示
		 if(err.message=='HTTP Error.'){
		 fid=err.file.id;
		 $("#file-"+fid+" td:eq(1)").html("<font color=red>系统出错，代码"+err.code+"</font>");
		 $("#file-"+fid+" td:eq(2)").html('<a onclick=deling("'+fid+'")>删除</a>');
		 return false;
		 }
		 layer.alert("<strong>"+err.message+"</strong>",{icon:5});
    });

});
</script>
<style>
.item-btn{text-align:center;padding-bottom:15px;}
.layui-eva .layui-form-label{width:90px;padding-left:0;}
.layui-eva .layui-form-item{	margin-top: 0;}
</style>
<form class="layui-form layui-font14 layui-eva" name="" action>
<div class="layui-form-item" style='margin:15px 0'>
<div class="upload-box" style='margin:0 15px'>
<p>
<textarea name="txt" class="layui-textarea checkLen" lay-verify="txtrequire" style='height:100px;width:96%;margin:10px 2% 0 2%' placeholder="(必填)本次的回复评价具体内容,不少于10个字"></textarea>
</p>

	<div class="container">
				<div class="statusBar" style='line-height:36px;'>
				<div class="info">图片非必传！限上传5个,单个大小上限2M,支持格式：jpg,png,gif</div>
					<div class="btns">
					<a id="browse">选择图片</a>
					</div>
				</div>
<table  class="fu_list" id='pluing' style='display:none;' >
            <thead>
              <tr>
                <td width="65%">待传队列（<u>0</u>）</td>
				<td width="25%" align="center"></td>
                <td width="10%" align="center">操作</td>
              </tr>
            </thead>
            <tbody id="FileListing">
            </tbody>
          </table>
	</div>
</div>
</div>

<div class="layui-form-item item-btn">
    <input type="button" class="layui-btn layui-btn-danger lay-submit" lay-submit=""  value="确认提交" />
</div>
<input type="hidden" name="layer" value="1">
<input type="hidden" name="bh" value="{$data.number}">
<input type="hidden" name="role" value="{$data.role}">
<input type="hidden" name="object" value="{$data.object}">
<input type="hidden" name="action" value="reply">
<input type="hidden" name="passkey" value="{:passkey()}">
</form>
<script type="text/javascript">
layer.title('<font style="font-weight:700;font-size:14px;">回复评价</font>');
layui.use('form', function(){
var form = layui.form();
form.verify({
  txtrequire: function(value){
    if(value.length<10){
      return '回复评价内容不能少于10个字';
    }
}
});
form.on('submit', function(data) {
	layer.load();
	dform(data.field,'evaluation',function(datas){
		if(datas.state<0 && uploader.total.queued>0){
			Rsdata=datas;
			progress();
			$('#progress-upload').html(uploader.total.queued);
			uploader.start();
		}else{
			Rs(datas);
		}
	});
	return false;
});


});
</script>
